<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="../static/plugins/jquery-easyui-1.10.19/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../static/plugins/jquery-easyui-1.10.19/themes/icon.css">
    <script type="text/javascript" src="../static/plugins/jquery-easyui-1.10.19/jquery.min.js"></script>
    <script type="text/javascript" src="../static/plugins/jquery-easyui-1.10.19/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../static/plugins/jquery-easyui-1.10.19/datagrid-export.js"></script>
    <script type="text/javascript" src="../static/plugins/jquery-easyui-1.10.19/locale/easyui-lang-zh_CN.js"></script>

    <script>
        $(function () {
            $('#dg').datagrid({
                url: '/lab00/ServletAchievement?action=getdglist',
                toolbar: '#tb',
                pagination: true,
                fit: true,
                singleSelect: true,//分页
                columns: [[
                    {field: 'sno', title: '学号', width: 100},
                    {field: 'sname', title: '姓名', width: 100},
                    {field: 'cno', title: '课程号', width: 100},
                    {field: 'cname', title: '课程名', width: 100},
                    {field: 'teacher', title: '教师', width: 100},
                    {field: 'semester', title: '学期', width: 100},
                    {field: 'grades', title: '成绩', width: 100}
                ]]
            });

            // //删除功能
            // $('#btnDelete').click(function () {
            //     if ($('#dg').datagrid('getSelected') == null) {
            //         $.messager.alert('提示', '请选择要删除的数据', 'warning');
            //         return;
            //     }
            //     $.messager.confirm('提示', '是否要删除该数据？', function (r) {
            //         if (r) {
            //             let row = $('#dg').datagrid('getSelected')
            //             $.ajax({
            //                 type: "GET",
            //                 url: "/lab00/ServletAchievement?action=delete",
            //                 data: {sno: row.sno},
            //                 success: function (ret) {
            //                     let result = eval("(" + ret + ")");
            //                     if (result.code == '200') {
            //                         $.messager.show({
            //                             title: '提示',
            //                             msg: result.msg,
            //                             timeout: 2000,
            //                             showType: 'slide'
            //                         });
            //                         $('#dg').datagrid('reload');
            //
            //                     } else {
            //                         $.messager.alert('提示', result.msg, 'warning');
            //                         alert(result.msg);
            //                     }
            //
            //                 }
            //             })
            //
            //         }
            //     })
            // })

            //编辑功能
            $('#btnEdit').click(function () {
                if ($('#dg').datagrid('getSelected') == null) {
                    $.messager.alert('提示', '请选择要编辑的数据', 'warning');
                    return;
                }
                $('#dd').dialog({
                    title: '编辑数据',
                    width: 500,
                    height: 350,
                    closed: false,
                    cache: false,
                    href: 'achievementform.jsp?action=edit&r=' + Math.random(),
                    modal: true,
                    buttons: [{
                        text: '保存',
                        iconCls: 'icon-save',
                        handler: function () {
                            let isOk = $('#ff').form('validate');
                            if (isOk) {
                                $.messager.confirm('确认', '是否确认编辑？', function (r) {
                                    if (r) {
                                        SaveData('update');
                                    }
                                });
                            }
                        }
                    }, {
                        text: '退出',
                        iconCls: 'icon-back',
                        handler: function () {
                            $('#dd').dialog('close');

                        }
                    }]
                });
            })

            // //添加功能
            // $('#btnAdd').click(function () {
            //     $('#dd').dialog({
            //         title: '新增数据',
            //         width: 480,
            //         height: 350,
            //         closed: false,
            //         cache: false,
            //         href: 'achievementform.jsp?action=add&r=' + Math.random(),
            //         modal: true,
            //         buttons: [{
            //             text: '保存',
            //             iconCls: 'icon-save',
            //             handler: function () {
            //                 let isOk = $('#ff').form('validate');
            //                 if (isOk) {
            //                     $.messager.confirm('确认', '是否确认添加？', function (r) {
            //                         if (r) {
            //                             SaveData('add');
            //
            //                         }
            //                     })
            //                 }
            //             }
            //         }, {
            //             text: '退出',
            //             iconCls: 'icon-back',
            //             handler: function () {
            //                 $('#dd').dialog('close');
            //
            //             }
            //         }]
            //     });
            // })

            //导出功能
            $('#btnexport').click(function (){
                $('#dg').datagrid("toExcel", "成绩信息.xls");
            })

            //添加和的保存
            function SaveData(action) {

                $.messager.progress();	// display the progress bar
                $('#ff').form('submit', {
                    url: '/lab00/ServletAchievement?action=' + action,
                    onSubmit: function () {
                        var isValid = $(this).form('validate');
                        if (!isValid) {
                            $.messager.progress('close');	// hide progress bar while the form is invalid
                        }
                        return isValid;	// return false will stop the form submission
                    },
                    success: function (data) {
                        let result = eval('(' + data + ')');
                        if (result.code == '200') {
                            $.messager.alert('提示', result.msg, 'info');
                            $('#add').dialog('close');
                            $('#dg').datagrid('reload');
                        } else
                            $.messager.alert('提示', result.msg, 'warning')
                        $.messager.progress('close');
                        // hide progress bar while submit successfully
                    }
                });
            }
        })
    </script>

</head>
<body class="easyui-layout">
<div data-options="region:'center',border:false">
    <table id="dg"></table>
</div>
<div id="dd"></div>
<div id="tb" style="height:auto">
    <table>
        <tr>
<%--            <td><a id="btnAdd" href="javascript:void(0)" class="easyui-linkbutton"--%>
<%--                   data-options="iconCls:'icon-add',plain:true">添加</a></td>--%>

            <td><a id="btnEdit" href="javascript:void(0)" class="easyui-linkbutton"
                   data-options="iconCls:'icon-edit',plain:true">编辑</a>
            </td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
<%--            <td><a id="btnDelete" href="javascript:void(0)" class="easyui-linkbutton"--%>
<%--                   data-options="iconCls:'icon-remove',plain:true">删除</a>--%>
<%--            </td>--%>
<%--             <td>--%>
<%--                 <div class="datagrid-btn-separator"></div>--%>
<%--            </td>--%>
            <td><a id="btnexport" href="javascript:void(0)" class="easyui-linkbutton"
                   data-options="iconCls:'icon-save',plain:true">导出</a>
            </td>
            <td>
                <input id="btnSearch" class="easyui-searchbox" data-options="prompt:'请输入学号',searcher:doSearch">
            </td>
            <script>
                function doSearch(value){
                    console.log("1111")
                    if (value == ""){
                        $.messager.alert('提示', '请选择要搜索的数据', 'warning');
                    }else {
                        $.ajax({
                            type:"POST",
                            url:"/lab00/ServletAchievement?action=search",
                            data:{key1:value},
                            success:function (ret)
                            {
                                debugger
                                let result = eval("(" +ret+")");
                                if(result !="404")
                                    $('#dg').datagrid({
                                        url: '/lab00/ServletAchievement?action=search',
                                        method: 'post',
                                        queryParams: {
                                            key1: value,
                                        },
                                        toolbar: '#tb',
                                        fit: true,
                                        columns: [[
                                            {field: 'sno', title: '学号', width: 100},
                                            {field: 'sname', title: '姓名', width: 100},
                                            {field: 'cno', title: '课程号', width: 100},
                                            {field: 'cname', title: '课程名', width: 100},
                                            {field: 'teacher', title: '教师', width: 100},
                                            {field: 'semester', title: '学期', width: 100},
                                            {field: 'grades', title: '成绩', width: 100}
                                        ]],
                                        onLoadSuccess: function(data){ // 数据加载成功后的回调函数
                                            console.log("Data loaded successfully.");
                                        }
                                    });

                                else{
                                    $.messager.alert('提示',"没有查询到！", 'warning');
                                }
                                // console.log(result);
                            }
                        })
                    }







                }
            </script>
        </tr>
    </table>
</div>
</body>
</html>
<%--style="width:40%;max-width:400px;padding:30px 60px;"--%>
<%--style="width:100%"--%>